<%--

<!------------------------------------------------------------------------------
 - Copyright 2007 CORE Solutions Limited
 - All rights reserved.
 - PROPRIETARY AND CONFIDENTIAL INFORMATION.
 - Use is subject to license terms.
 -
 - FUNCTION ID      :   POPUP_CATALOG_TREE
 - AUTHOR           :   Saint Peng 
 - DATE CREATE      :   2007/04/05
 - DESCRIPTION      :   a PAGE-EDIT CONTENT JSP file for the function, POPUP_CATALOG_TREE
 -                  :   
 -                  :   
 -                  :   
 -
 - MODIFICATION HISTORY:
 - DATE         AUTHOR          VERSION NO.         COMMENT
 - -----------  --------------  ------------------  -------------------
 - 2007/04/05   Saint Peng      1.0                 source is generated.
 -
 -
 -
------------------------------------------------------------------------------->

--%>
<%@ include file="/jsp/com/erp/app/common/jsp/directives_include.jsp"%>

<%@ page  import="com.erp.app.catalog.catalogTreePopup.web.PopupCatalogTreeAction" %>
<%@ page  import="com.erp.app.catalog.catalogTreePopup.web.PopupCatalogTreeRow" %>

<%@ include file="/jsp/com/erp/app/common/jsp/html_include.jsp"%>

<% try { %>

<jsp:useBean id="popupCatalogTreeForm" scope="session" type="com.erp.app.catalog.catalogTreePopup.web.PopupCatalogTreeForm" />

<%
ArrayList popupCatalogTreeList = popupCatalogTreeForm.getMultiRows();
pageContext.setAttribute("popupCatalogTreeList", popupCatalogTreeList);
rowReadOnly = false;
TableSchema ts = popupCatalogTreeForm.getTs();
boolean needParent = false;
boolean needChild = false;
if(session.getAttribute(ProjectConstants.POP_UP_CATALOG_TREE_CHECKBOX_NEED_PARENT) != null
	&& ((String)session.getAttribute(ProjectConstants.POP_UP_CATALOG_TREE_CHECKBOX_NEED_PARENT)).equals(
		ProjectConstants.GENERIC_YES)) {
	needParent = true;
	session.removeAttribute(ProjectConstants.POP_UP_CATALOG_TREE_CHECKBOX_NEED_PARENT);
}

if(session.getAttribute(ProjectConstants.POP_UP_CATALOG_TREE_CHECKBOX_NEED_CHILD) != null
	&& ((String)session.getAttribute(ProjectConstants.POP_UP_CATALOG_TREE_CHECKBOX_NEED_CHILD)).equals(
		ProjectConstants.GENERIC_YES)) {
	needChild = true;
	session.removeAttribute(ProjectConstants.POP_UP_CATALOG_TREE_CHECKBOX_NEED_CHILD);
}

%>



<script language="javascript">

	function doLoad() {
		<%
			if (!CommonUtil.isEmpty(popupCatalogTreeForm.getPageEvent())) {
				if (popupCatalogTreeForm.getPageEvent().equals(PopupCatalogTreeAction.ACTION_SELECT_FINISH)) {
					out.println("window.opener.doSubmit('doNothing');");
					out.println("self.close();");
				}
			}
		if (CommonUtil.nullToString((String)session.getAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE)).equals(ProjectConstants.GENERIC_YES)) {
			session.removeAttribute(ProjectConstants.SESSION_ALERT_AFTER_SAVE);
			out.println("alert('Records saved.');");
		}
		%>
	}

	function checkNodeId(chName) {
		var s = document.getElementsByName(chName);
		var str=",";
		for (i=0;i<s.length;i++){
		 if(s[i].checked)str= str + s[i].value+",";
		}
		doSubmit('<%=PopupCatalogTreeAction.ACTION_SELECT_FINISH%>', str);
	}

		jTree1 = new jTree('jTree1', 'jTreeDisp');

</script>


<body onLoad="javascript:doLoad();autofill_init();">
<html:form action="/popupCatalogTree">
<html:hidden property="pageEventSrc"/>
<html:hidden property="pageEvent"/>
<html:hidden property="pageMode"/>


<table class="table_top" nowrap>



<tr>
	<td>
		<input type = "button" value = "OK" onClick = "javascript:checkNodeId('cbjTree1');" class="button1">
		<input type = "button" value = "Cancel" onClick = "javascript:window.opener.doSubmit('doNothing');self.close();" class="button1">
		<input type="button" value="Open All" class="button1" name="openAll" onclick="javascript: jTree1.openAll();" / >
		<input type="button" value="Close All" class="button1" name="closeAll" onclick="javascript: jTree1.closeAll();" / >
		<input type="button" value="Select All" class="button1" name="selectAll" onclick="javascript: jTree1.selectAll();" / >
		<input type="button" value="Dis-Select All" class="button1" name="disSelectAll" onclick="javascript: jTree1.disSelectAll();" / >
	</td>
</tr>

<tr>
	<td><font color='red'><html:errors/></font></td>
</tr>

</table>
<div class='jTree' id='jTreeDisp'>
</div>
<table>
<tr>
	<td>
		<input type = "button" value = "OK" onClick = "javascript:checkNodeId('cbjTree1');" class="button1">
		<input type = "button" value = "Cancel" onClick = "javascript:window.opener.doSubmit('doNothing');self.close();" class="button1">
		<input type="button" value="Open All" class="button1" name="openAll" onclick="javascript: jTree1.openAll();" / >
		<input type="button" value="Close All" class="button1" name="closeAll" onclick="javascript: jTree1.closeAll();" / >
	</td>
</tr>
</table>
</html:form>
	<script type="text/javascript">
		<!--

		jTree1.config.useCheckbox = true;
//		jTree1.config.checkboxNeedParent = <%=needParent%>;
//		jTree1.config.checkboxNeedChild = <%=needChild%>;
		jTree1.checkbox.trueSetParent = <%=popupCatalogTreeForm.isTrueSetParent()%>;
		jTree1.checkbox.falseSetParent = <%=popupCatalogTreeForm.isFalseSetParent()%>;
		jTree1.checkbox.trueSetChild = <%=popupCatalogTreeForm.isTrueSetChild()%>;
		jTree1.checkbox.falseSetChild = <%=popupCatalogTreeForm.isFalseSetChild()%>;
		jTree1.checkbox.needChild = <%=popupCatalogTreeForm.isNeedChild()%>;

		jTree1.add(0,-1,'Search Category','item_title');

		<logic:iterate id="popupCatalogTreeRow" name="popupCatalogTreeList" indexId="idx" offset="<%=String.valueOf(popupCatalogTreeForm.getSidx())%>">

		<%
			PopupCatalogTreeRow row = (PopupCatalogTreeRow) popupCatalogTreeRow;
			String className = "";
			if((row != null)) {
				if(row.getCatalogLevel() == "1"){
					className = "item_line";
				}else if(row.getCatalogLevel() == "2"){
					className = "item_category";
				}else if(row.getCatalogLevel() == "3"){
					className = "item_class";
				}
		%>
			jTree1.add(<bean:write name="popupCatalogTreeRow" property="nodeId" filter="true"/>,<bean:write name="popupCatalogTreeRow" property="parentNodeId" filter="true"/>,'<bean:write name="popupCatalogTreeRow" property="description" filter="true"/>','<%=className%>');
		<%
			}
		%>
		</logic:iterate>
	
	
		jTree1.refresh();

		//-->
	</script>

<% } catch(Exception e) { e.printStackTrace(); } %>
